package com.it.flowable.config;

import com.alibaba.fastjson.JSON;
import org.flowable.engine.ProcessEngine;
import org.flowable.engine.ProcessEngines;
import org.flowable.engine.RepositoryService;
import org.flowable.engine.repository.Deployment;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import java.io.InputStream;

@Component
public class BpmLeaveDeploymentRunner implements CommandLineRunner {

    @Override
    public void run(String... args) throws Exception {
        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
        RepositoryService repositoryService = processEngine.getRepositoryService();

        try (InputStream inputStream = BpmLeaveDeploymentRunner.class.getResourceAsStream("/processes/advance-monitor-qj.bpmn20.xml")) {
            System.out.println("inputStream >>>>>> " + JSON.toJSONString(inputStream));
            Deployment deployment = repositoryService.createDeployment()
                    .addInputStream("advance-monitor-qj.bpmn20.xml", inputStream)
                    .deploy();

            System.out.println("Deployment ID: " + deployment.getId());
        }
    }

}
